package aod.android.com.bernay.mine.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.google.gson.Gson;

import java.io.IOException;

import aod.android.com.bernay.R;
import aod.android.com.bernay.base.BernayBaseActivity;
import aod.android.com.bernay.http.BernayApi;
import aod.android.com.bernay.http.BernayCallback;
import aod.android.com.bernay.mine.module.ProblemDetailBean;
import aod.android.com.bernay.util.SharePreUtils;
import chen.lion.hilib.util.LogUtils;
import chen.lion.hilib.view.bind.HiView;

/**
 * @author crated by zhixianuanyang on 2019/4/17 13:35
 * @Email jamesKing0812@gmail.com
 */
public class ProblemDetailActivity extends BernayBaseActivity {

    @HiView(R.id.tv_question)
    TextView mQuestion;

    @HiView(R.id.tv_answer)
    TextView mAnswer;

    private String id = "";
    private String content = "";

    private Bundle bundle;

    private ProblemDetailBean problemDetailBean;

    @Override
    protected int initLayout() {
        return R.layout.activity_problem_detail;
    }

    @Override
    protected void initData() {
        initTitle("常见问题");
        //获取上个页面数据信息
        bundle = getIntent().getExtras();
        id = bundle.getString("id");
        content = bundle.getString("content");
        mQuestion.setText(content);
        //获取页面id
        getProblemDetail();
    }

    private void getProblemDetail() {
        String userId = SharePreUtils.newInstance(ProblemDetailActivity.this).getUserId();
        String token =  SharePreUtils.newInstance(ProblemDetailActivity.this).getToken();
        BernayApi.http().getQuestionorAnsewr(userId, token, id,new BernayCallback() {
            @Override
            public void onJsonData(String json) {
                problemDetailBean = new Gson().fromJson(json, ProblemDetailBean.class);
                if (1==problemDetailBean.getStatus() && problemDetailBean.getData() != null){
                    mAnswer.setText(problemDetailBean.getData().getContent());
                }
            }

            @Override
            public void onHttpFailure(IOException e) {
                LogUtils.json(new Gson().toJson(e));
            }
        });
    }
}
